package org.dbpt.performance;

public class DataGenerator {
	
	private static final int CAPITILIZED_LETTERS_SYMBOLS_COUNT = 'Z' - 'A' + 1;
	private static final int WORD_SYMBOLS_COUNT = 2 * ('Z' - 'A' + 1);
	private static final int WORD_AND_DIGITS_SYMBOLS_COUNT = 2 * ('Z' - 'A' + 1) + ('9' - '0' + 1);
	
	/**
	 * Utility class so no instance should be created. 
	 */
	private DataGenerator() {
	}

	public static String generateWord(int len) {
		StringBuffer sb = new StringBuffer(len);
		for(int i = 0; i < len; i++) {
			int r = (int) (Math.random() * WORD_SYMBOLS_COUNT);
			char c;
			if(r < CAPITILIZED_LETTERS_SYMBOLS_COUNT) {
				c = (char) ('A' + r);
			} else {
				c = (char) ('a' + r - CAPITILIZED_LETTERS_SYMBOLS_COUNT);
			}
			sb.append(c);
		}
		return sb.toString();
	}

	public static String generateWordWithDigits(int len) {
		StringBuffer sb = new StringBuffer(len);
		for(int i = 0; i < len; i++) {
			int r = (int) (Math.random() * WORD_AND_DIGITS_SYMBOLS_COUNT);
			char c;
			if(r < CAPITILIZED_LETTERS_SYMBOLS_COUNT) {
				c = (char) ('A' + r);
			} else if(r < WORD_AND_DIGITS_SYMBOLS_COUNT){
				c = (char) ('a' + r - CAPITILIZED_LETTERS_SYMBOLS_COUNT);
			} else {
				c = (char)('0' + r - WORD_AND_DIGITS_SYMBOLS_COUNT);
			}
			sb.append(c);
		}
		return sb.toString();
	}

	public static String generateString(int len) {
		StringBuffer sb = new StringBuffer(len);
		for(int i = 0; i < len; i++) {
			sb.append((char)('A' + Math.random() * ('Z' - 'A')));
		}
		return sb.toString();
	}

	public static int generateInt(int size) {
		return (int) (Math.random() * size);
	}
}
